package com.punch.oauth.controller;


import com.punch.common.model.Result;
import com.punch.common.simple.redis.utils.RedisUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * 生产环境获取accesstoken
 */
@RestController
@Slf4j
public class WxAccessTokenController {


    @Value("${punch.wx.appid}")
    private String wxAppid;
    @Resource
    private RedisUtil<String> redisUtil;

    @GetMapping(value = "/oauth/wx-accesstoken", produces = "application/json;charset=UTF-8")
    public Result<String> getWxAccessToken() {
        StringBuilder sb = new StringBuilder();
        sb.append("wx:").append(wxAppid).append(":accessToken");
        return Result.succeed(redisUtil.getValue(sb.toString()), "");
    }
}
